package view.WelcomePanels.SubPanels.MainButtonPanels;

import domain.WelcomeController;
import dto.ResetPasswordDTO;
import dto.WelcomeDTO;
import java.awt.event.ActionEvent;
import java.net.ConnectException;
import javax.swing.JOptionPane;

/**
 *
 * @author Joachim
 */
public class ResetPasswordButtonPanel extends MainButtonPanel {
    
    public ResetPasswordButtonPanel(WelcomeDTO dto, WelcomeController controller) {
        super(dto, controller, "Reset Password");
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        try {
            boolean resetPasswordSuccess = super.controller.resetPassword((ResetPasswordDTO)super.dto);
            if(resetPasswordSuccess)
                JOptionPane.showMessageDialog(null, "Your password has been reset, check your inbox.");
            else
                JOptionPane.showMessageDialog(null, "Password reset failed.");
        }
        catch(IllegalArgumentException iae) {
            JOptionPane.showMessageDialog(null, iae.getMessage());
        }
        catch(ConnectException ce) {
            JOptionPane.showMessageDialog(null, ce.getMessage());
        }
    }
    
}
